<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="app" uri="http://www.wanrenhui.com"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@include file="/res/include/base-head.jsp"%>
<%@include file="/res/include/jquery-easyui.jsp"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/coupon/couponBase.js"></script>
</head>
<body>
<form id="data-form">
	<div class="form_item">
	<input type="hidden" value="${detailVo.id}" name="id"/>
		<dl>
			<dt>名称：</dt>
			<dd>
				<input  type="text" id="name" name="name" style="width:400px;" value="${detailVo.name}"/>
			</dd>
		</dl>
		<dl>
			<dt>描述：</dt>
			<dd>
				<textarea class="txt grid-75" id="remark" name="remark" oninput="admin.couponBase.netMsgChange('remark',360)" onpropertychange="admin.couponBase.netMsgChange('remark',360)" rows="4" >${detailVo.remark}</textarea>
			</dd>
		</dl>
		<dl>
			<dt>发行量：</dt>
			<dd>
				<input  type="text" id="quantity" name="quantity" data-options="required:true" value="${detailVo.quantity}"/>  此种优惠卷发行数量，用户获取一张就少一张
			</dd>
		</dl>
		<dl>
			<dt>满多少金额：</dt>
			<dd>
				<input  type="text" id="fullPrice" name="fullPrice" value="${detailVo.fullPrice}"/> 满多少金额，只支持商城
			</dd>
		</dl>
		<dl>
			<dt>减多少金额：</dt>
			<dd>
				<input  type="text" id="minusPrice" name="minusPrice" value="${detailVo.minusPrice}"/>  现金卷只需填这项
			</dd>
		</dl>
		<dl>
			<dt>金额：</dt>
			<dd>
				<input  type="text" id="price" name="price" value="${detailVo.price}"/>固定金额产品（0.01元奖品等），圈币金额（5圈币）
			</dd>
		</dl>
		<dl>
			<dt>是否圈币兑换：</dt>
			<dd>
				<input  type="radio" name="isQBuy" value="1" <c:if test="${detailVo.isQBuy == 1}">checked="checked"</c:if> />是
				<input  type="radio" name="isQBuy" value="2" <c:if test="${detailVo.isQBuy == 2}">checked="checked"</c:if>/>否
			</dd>
		</dl>
		<dl>
			<dt>使用截止日期：</dt>
			<dd>
				<input id="expireAt" type="text" class="txt easyui-datetimebox grid-15" name="expireAt" data-options="required:true,validType:'datetime'" value="${detailVo.expireAt}"/>
			</dd>
		</dl>
		<dl>
			<dt>优惠卷类型：</dt>
			<dd>
				<select name="bizzType" id="bizzType">
					<option value="10" <c:if test="${detailVo.bizzType == 10}">selected="selected"</c:if>>便利店优惠卷</option>
					<option value="9" <c:if test="${detailVo.bizzType == 9}">selected="selected"</c:if>>邻里店优惠卷</option>
					<option value="8" <c:if test="${detailVo.bizzType == 8}">selected="selected"</c:if>>周边商家优惠卷</option>
					<option value="5" <c:if test="${detailVo.bizzType == 5}">selected="selected"</c:if>>店铺优惠卷</option>
					<option value="6" <c:if test="${detailVo.bizzType == 6}">selected="selected"</c:if>>圈币优惠卷</option>
					<option value="2" <c:if test="${detailVo.bizzType == 2}">selected="selected"</c:if>>单商品优惠卷</option>
					<option value="3" <c:if test="${detailVo.bizzType == 3}">selected="selected"</c:if>>服务类目优惠卷</option>
				</select>
			</dd>
		</dl>
		<dl <c:if test="${detailVo.bizzType == 2 || detailVo.bizzType == 5}">style="display:none;"</c:if> id="showCommunityPage">
			<dt>适用(圈币兑换)社区：</dt>
			<dd>
			<div>
				<select name="communityId" id="communityId">
					<option value="">全部</option>
					<c:forEach var="item" items="${communityList}">
						<option value="${item.id}" <c:if test="${communityId == item.id}">selected="selected"</c:if>>${item.name}</option>
					</c:forEach>
				</select>
			</div>
			</dd>
		</dl>
		<dl <c:if test="${detailVo.bizzType != 5}">style="display:none;"</c:if> id="showPage1">
			<dt>店铺：</dt>
			<dd>
			<div>
				<select id="mallShopC2" onchange="getMallShopC(this.value,'2')">
					<option value="0" <c:if test="${communityId == 0}">selected="selected"</c:if>>圈圈商城</option>
					<c:forEach var="item" items="${communityList}">
						<option value="${item.id}" <c:if test="${communityId == item.id}">selected="selected"</c:if>>${item.name}</option>
					</c:forEach>
				</select>
				<select id="mallShop2">
					<c:forEach var="item" items="${mallList}">
						<option value="${item.id}" <c:if test="${shopId == item.id}">selected="selected"</c:if>>${item.name}</option>
					</c:forEach>
				</select>
			</div>
			</dd>
		</dl>
		<dl  id="showPage" <c:if test="${detailVo.bizzType != 2&&detailVo.bizzType != 3}">style="display:none;"</c:if>>
			<dt>产品：</dt>
			<dd>
			<div id="valuesMallShop" <c:if test="${detailVo.bizzType != 2}">style="display:none;"</c:if>>
				<select id="mallShopC" onchange="getMallShopC(this.value,'1')">
					<option value="0" <c:if test="${communityId == 0}">selected="selected"</c:if>>圈圈商城</option>
					<c:forEach var="item" items="${communityList}">
						<option value="${item.id}" <c:if test="${communityId == item.id}">selected="selected"</c:if>>${item.name}</option>
					</c:forEach>
				</select>
				<select id="mallShop" onchange="getMallShop(this.value)">
					<c:forEach var="item" items="${mallList}">
						<option value="${item.id}" <c:if test="${shopId == item.id}">selected="selected"</c:if>>${item.name}</option>
					</c:forEach>
				</select>
			</div>
			<div class="product_imglist img_imglist" id="valuesPage" <c:if test="${detailVo.bizzType!=2}">style="display:none;"</c:if>>
			<ui>
			<c:forEach var="item" items="${mallProductList}">
			<li>${fn:substring(item.name,0,6)}<p class='img'><img src="${item.imgItems[0].source }" alt='' /></p>${item.price}元
			<br/><input type='radio' value='${item.id}' name='baseVo' <c:if test="${detailVo.bizzId == item.id}">checked="checked"</c:if>/>
			</li>
			</c:forEach>
			</ui>
			</div>
			<div id="valuesHomemakingType" <c:if test="${detailVo.bizzType!=3}">style="display:none;"</c:if>>
				<select id="homemakingType1" onchange="getChildrenHomemakingType(this.value)">
					<c:forEach var="homemakingType" items="${homemakingTypes}">
						<option value="${homemakingType.id}" <c:if test="${homemakingType.id==detailVoHomeMakingTpye.parentId}">selected="selected"</c:if>>${homemakingType.name}</option>
					</c:forEach>
				</select>
				<select id="homemakingType2">
		        	<c:forEach var="homemakingType" items="${homemakingTypes2}">
		        		<option value="${homemakingType.id }" <c:if test="${homemakingType.id==detailVoHomeMakingTpye.id}">selected="selected"</c:if>>${homemakingType.name}</option>
		        	</c:forEach>
				</select>
			</div>
			</dd>
		</dl>
		<dl>
			<dt>注意：</dt>
			<dd>
				1.普通卷全场通用，商城、服务都可以用，只限减多少金额的卷，打折未开通。<br/>
				2.服务项目，只限减少多少金额的卷，打折未开通、满多少未开通。<br/>
				3.单商品优惠卷，可减多少金额劵、一口价，打折未开通。<br/>
			</dd>
		</dl>
		<p class="page_btn"><input type="button" id="saveBtn" value="保存" class="btn_blue" onclick="add();"/></p>
	</div>
</form>
</body>
<script type="text/javascript">
	function getMallProductList(shopId){
		if(shopId==null || shopId==''){
			$("#valuesPage").html(showPageValues.join(""));
			return;
		}
		var url = contextPath + '/coupon/base/getMallProductList';
		$.post(url, {shopId:shopId}, function(data) {
			var showPageValues=[];
			var list=data.map['list'];
			showPageValues.push("<ul>");
			for(var i=0;i<list.length;i++){
				var vo=list[i];
				if(vo.hasImg){
					showPageValues.push("<li>"+vo.name.substring(0,6)+"<p class='img'><img src="+vo.imgItems[0].source+" alt='' /></p>"+vo.price+"元");
				}else{
					showPageValues.push("<li>"+vo.name.substring(0,6)+"<br/>"+vo.price+"元");
				}
				showPageValues.push("<br/><input type='radio' value='"+vo.id+"' name='baseVo'/></li>");
				if(i!=0&&i%10==0){
					showPageValues.push("<br/>");
				}
			}
			showPageValues.push("</ul>");
			$("#valuesPage").html(showPageValues.join(""));
		});
	}
/* 	function getHomemakingTypeList(){
		var url = contextPath + '/coupon/base/getHomemakingTypeList';
		$.post(url, {}, function(data) {
			$("#showPage").show();
			var showPageValues=[];
			var list=data.map['list'];
			showPageValues.push("<ul>");
			for(var i=0;i<list.length;i++){
				var vo=list[i];
				if(vo.hasImg){
					showPageValues.push("<li>"+vo.name+"<p class='img'><img src="+vo.imgItems[0].source+" alt='' /></p>");
				}else{
					showPageValues.push("<li>"+vo.name+"</br>");
				}
				showPageValues.push("</br><input type='radio' value='"+vo.id+"' name='baseVo'/></li>");
				if(i!=0&&i%10==0){
					showPageValues.push("</br>");
				}
			}
			showPageValues.push("</ul>");
			$("#valuesPage").html(showPageValues.join(""));
		});
	} */
	function getChildrenHomemakingType(parentId) {
		if (parentId != "") {
			var data = {parentId:parentId}
			$.post(contextPath+'/coupon/base/getSecondHomemakingTypeList',data,function(data) {
				if(data.code==1) {
					var showPageValues=[];
					var list=data.map['list'];
					for(var i=0;i<list.length;i++){
						var vo=list[i];
						showPageValues.push("<option value="+vo.id+">"+vo.name+"</option>");
					}
					$("#homemakingType2").html(showPageValues.join(""));
				}
			});
		}
	}
	function getMallCategoryList(){
		var url = contextPath + '/coupon/base/getMallCategoryList';
		$.post(url, {}, function(data) {
			$("#showPage").show();
			var showPageValues=[];
			var list=data.map['list'];
			for(var i=0;i<list.length;i++){
				var vo=list[i];
				if(vo.hasImg){
					showPageValues.push("<li>"+vo.name+"<p class='img'><img src="+vo.imgItems[0].source+" alt='' /></p>");
				}else{
					showPageValues.push("<li>"+vo.name+"<br/>");
				}
				showPageValues.push("<br/><input type='radio' value='"+vo.id+"' name='baseVo'/></li>");
				if(i!=0&&i%10==0){
					showPageValues.push("<br/>");
				}
			}
			$("#valuesPage").html(showPageValues.join(""));
		});
	}
	function getMallShopList(communityId,type){
		var url = contextPath + '/coupon/base/getCMallList';
		$.post(url, {communityId:communityId}, function(data) {
			var showPageValues=[];
			var list=data.map['list'];
			for(var i=0;i<list.length;i++){
				var vo=list[i];
				showPageValues.push("<option value="+vo.id+">"+vo.name+"</option>");
			}
			if(type==1){
				$("#mallShop").html(showPageValues.join(""));
				getMallProductList(data.map['shopId']);
			}else if(type==2){
				$("#mallShop2").html(showPageValues.join(""));
			}
		});
	}
	function getMallShop(shopId){
		getMallProductList(shopId);
	}
	function getMallShopC(communityId,type){
		if(communityId =="0"){
			$("#communityId").val("");
		}else{
			$("#communityId").val(communityId);
		}
		getMallShopList(communityId,type);
	}
	function add(){
		var data = $('#data-form').form('jsonObject');
		if(data.name==null || data.name==''){
			top.showInfo('请填写 名称');
			return;
		}
		if(data.quantity==null || data.quantity==''){
			top.showInfo('请填写 发行量');
			return;
		}
		if(data.expireAt==null || data.expireAt==''){
			top.showInfo('请填写 截止日期');
			return;
		}
		
		if($("#bizzType").val()==4){
			var categoryId=$("input[name='baseVo']:checked").val();
			if(null==categoryId||''==categoryId){
				top.showInfo('请选择类目');
				return;
			}
			data.categoryId=categoryId;
		}else if($("#bizzType").val()==2){
			var bizzId=$("input[name='baseVo']:checked").val();
			if(null==bizzId||''==bizzId){
				top.showInfo('请选择商品');
				return;
			}
			data.bizzId=bizzId;
		}else if($("#bizzType").val()==3){
			var categoryId=$("#homemakingType2").val();
			if(null==categoryId||''==categoryId){
				top.showInfo('请选择类目');
				return;
			}
			data.categoryId=categoryId;
		}else if($("#bizzType").val()==5){
			var bizzId=$("#mallShop2").val();
			if(null==bizzId||''==bizzId){
				top.showInfo('请选择店铺');
				return;
			}
			
			data.bizzId=bizzId;
		}
		var url = contextPath + '/coupon/base/update';
		 $.post(url, data, function(data) {
			top.addTab("",'优惠卷列表', contextPath+'/coupon/base/list');
		}); 
	}
	$("#bizzType").change(function(){
		$("#communityId").val("");//更改 优惠卷类型时重置-适用社区(全部)
		  if(this.value==2){//商品
			  $("#showCommunityPage").hide();
			  $("#showPage").show();
			  $("#valuesPage").show();
			  $("#showPage1").hide();//隐藏-店铺
			  $("#valuesMallShop").show();
			  $("#valuesHomemakingType").hide();
			  getMallProductList($("#mallShop").val());
		  }else if(this.value==1){//优惠卷base
			  $("#showCommunityPage").show();
			  $("#showPage").hide();
			  $("#bizzId").value="";
			  $("#categoryId").value="";
		  }else if(this.value==3){//服务类型
			  $("#showCommunityPage").hide();
			  $("#showCommunityPage").show();
			  $("#showPage").show();
			  $("#valuesHomemakingType").show();
			  $("#valuesPage").hide();
			  $("#valuesMallShop").hide();
			  $("#showPage1").hide();
		  }else if(this.value==4){//商城类型
			  $("#showCommunityPage").show();
			  getMallCategoryList();
		  }else if(this.value==6||this.value==8||this.value==9||this.value==10){//6-圈币;8-周边商家;9-邻里店;10-便利店
			  $("#showCommunityPage").show();
			  $("#showPage").hide();
			  $("#showPage1").hide();
			  $("#bizzId").value="";
			  $("#categoryId").value="";
		  }else if(this.value==5){//店铺
			  $("#showCommunityPage").hide();
			  $("#showPage").hide();
			  $("#showPage1").show();
			  $("#bizzId").value="";
			  $("#categoryId").value="";
		  }
	});
</script>
</html>
